package com.example.myyiyanmengjava.http;

import com.example.myhttplibrary.callback.BaseCallBack;
import com.example.myhttplibrary.utils.JsonUtils;

public abstract class HttpCallBack<T> extends BaseCallBack<T> {

    BaseResponse baseResponse = null;

    @Override
    protected T onConvert(String result) {
        T t = null;
        baseResponse = JsonUtils.jsonToClass(result, BaseResponse.class);
        if (isCodeSuccess()) {
            t = convert(baseResponse.getData());
        } else {
            error(baseResponse.errmsg, baseResponse.errcode);
        }
        return t;
    }
    public boolean isCodeSuccess() {
        return baseResponse.errcode == 0;
    }
}
